package o2o.task.jPush;

import com.jinyou.utils.common.ValidateUtil;
import com.jinyouapp.client.push.JPushClient;
import jPush.dao.JPushMessage;
import o2o.cache.agent.ShopAgentRelationMemory;
import o2o.cache.order.OrderInfoMemory;
import o2o.cache.postman.CityPostmanMemory;
import o2o.cache.shop.ShopMemory;
import o2o.cache.sys.SysCustomerCache;
import o2o.dao.PO.common.UserType;
import o2o.postman.model.CityPostman;
import o2o.company.model.ShopInfo;
import o2o.dao.PO.sys.SysCustomerInfo;
import o2o.system.data.SHOP_MANAGE_TYPE_FREE_OR_AGENT;
import o2o.system.data.SYS_SETTINGS;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

//每天0点重新加载一次每日订单编号
@Component
public class JPushTask {

    //需要推送的列表
    public static List<JPushMessage> jPushMessageList = new ArrayList<JPushMessage>();

    //定时执行（需要推送的列表）
    //秒  分  时  日  月  星期几  年
    @Scheduled(cron = "0/10 * * * * *")
    public void jPushThread() {
        if (null == SYS_SETTINGS.IS_PUSH_WITH_JPUSH) {
//            System.out.println("未设置推送");
            return;
        }

        if (0 == 1 - SYS_SETTINGS.IS_PUSH_WITH_JPUSH) {         // 开启极光推送

            if (jPushMessageList.size() > 0) {
                List<JPushMessage> tempList = new ArrayList<JPushMessage>(jPushMessageList.size());
                synchronized (jPushMessageList) {
                    if (jPushMessageList.size() > 0) {
                        tempList.addAll(jPushMessageList);
                        jPushMessageList.clear();
                    }
                }

                if (null != tempList && tempList.size() > 0) {
                } else {
                    return;
                }

                String sysAppKey = SysCustomerCache.getInstance().getDefaultKey();
                SysCustomerInfo info = SysCustomerCache.getInstance().getInfo(sysAppKey);
                String jpushPhonePrefix = sysAppKey;
                if (null != info && ValidateUtil.isNotNull(info.getJpushPhonePrefix())) {
                    jpushPhonePrefix = info.getJpushPhonePrefix();
                }

                for (int i = 0; i < tempList.size(); i++) {
                    if (null == tempList.get(i)) {
                        continue;
                    }

                    String username = tempList.get(i).getUsername();
//                    List<String>uList = tempList.get(i).getUsernameList();
//                    HashSet<String> usernameList = new HashSet<>();
//                    for (int j = 0; j < uList.size(); j++) {
//                        if(null==uList.get(i)){
//                            continue;
//                        }
//                        usernameList.add(uList.get(i));
//                    }

                    HashSet<String> userSet = new HashSet<>();
                    if (ValidateUtil.isAbsList(tempList.get(i).getUsernameList())) {
                        userSet.addAll(tempList.get(i).getUsernameList());
                    }


                    if (ValidateUtil.isNotAbsInteger(tempList.get(i).getPushUserType())) {
                        continue;
                    }
                    switch (tempList.get(i).getPushUserType()) {
                        case UserType.USER: {//用户
                            if (null == SYS_SETTINGS.IS_PUSH_WITH_JPUSH_2_USER) {
                                continue;
                            }
                            if (0 != 1 - SYS_SETTINGS.IS_PUSH_WITH_JPUSH_2_USER) {
                                continue;
                            }

                        }
                        break;
                        case UserType.SHOP_OWNER: {//店家
                            if (null == SYS_SETTINGS.IS_PUSH_WITH_JPUSH_2_SHOP) {
                                continue;
                            }
                            if (0 != 1 - SYS_SETTINGS.IS_PUSH_WITH_JPUSH_2_SHOP) {
                                continue;
                            }


                            if (tempList.get(i).getIsCitySeller() && ValidateUtil.isNotNull(tempList.get(i).getCity())) {//如果是推给某个城市的
                                // List<ShopInfo> postmanList = ShopMemory.getInstance().list(tempList.get(i).getCity(), null, null, null, false);
                                List<ShopInfo> postmanList = ShopMemory.getInstance().list(false, null, tempList.get(i).getCity(), null, null, null, true, false, false, false);
                                if (ValidateUtil.isAbsList(postmanList)) {
                                    if (null == userSet) {
                                        userSet = new HashSet<>();
                                    }

                                    for (int j = 0; j < postmanList.size(); j++) {
                                        if (null == postmanList.get(j)) {
                                            continue;
                                        }
                                        if (0 != 1 - postmanList.get(j).getIsWork()) {
                                            continue;
                                        }
                                        System.out.println("推给店铺：" + postmanList.get(j).getOwnUsername());
                                        userSet.add(postmanList.get(j).getOwnUsername());
                                    }
                                }
                            }
                        }
                        break;
                        case UserType.POSTMAN: {//配送员
                            if (tempList.get(i).getIsCitySeller() && ValidateUtil.isNotNull(tempList.get(i).getCity())) {//如果是推给某个城市的
//                                List<CityPostman> postmanList = CityPostmanMemory.getInstance().listOfCity(tempList.get(i).getCity());
                                List<CityPostman> postmanList = CityPostmanMemory.getInstance().listOfCity(tempList.get(i).getCity(), 2, null, null, null, null, null, null);
                                if (ValidateUtil.isAbsList(postmanList)) {
                                    if (null == userSet) {
                                        userSet = new HashSet<>();
                                    }

                                    for (int j = 0; j < postmanList.size(); j++) {
                                        if (null == postmanList.get(j)) {
                                            continue;
                                        }
                                        if (0 != 1 - postmanList.get(j).getIsWork()) {
                                            continue;
                                        }
                                        System.out.println("推给配送员：" + postmanList.get(j).getUsername());
                                        userSet.add(postmanList.get(j).getUsername());
                                    }
                                }
                            }
                            if (null == SYS_SETTINGS.IS_PUSH_WITH_JPUSH_2_POSTMAN) {
                                continue;
                            }
                            if (0 != 1 - SYS_SETTINGS.IS_PUSH_WITH_JPUSH_2_POSTMAN) {
                                continue;
                            }
                        }
                        break;
                        default: {
                            continue;
                        }
                    }


                    //推给某人
                    if (ValidateUtil.isNotNull(username)) {
//                        jPushServiceInterface.pushOneUser(username, tempList.get(i).getTitle(), tempList.get(i).getContent(), tempList.get(i).getPushUserType());

                        try {
                            String subType = tempList.get(i).getJpSubType();
                            if (ValidateUtil.isNull(subType)) {
                                subType = "";
                            }
                            JPushClient.getInstance().setSysCustomer(sysAppKey + "-" + tempList.get(i).getPushUserType() + subType).setPhone(username).setTitle(tempList.get(i).getTitle()).setContent(tempList.get(i).getContent()).pushByAlias();

                            //智慧商户
                            JPushClient.getInstance().setSysCustomer("o2o_jinyou-" + tempList.get(i).getPushUserType() + subType).setPhone(jpushPhonePrefix + username).setTitle(tempList.get(i).getTitle()).setContent(tempList.get(i).getContent()).pushByAlias();
                            System.out.println("推送：" + username + ";" + sysAppKey + "-" + tempList.get(i).getPushUserType() + subType);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                    //推给某些人
                    if (null != userSet && userSet.size() > 0) {
//                        jPushServiceInterface.pushSomeUser(usernameList, tempList.get(i).getTitle(), tempList.get(i).getContent(), tempList.get(i).getPushUserType());

                        String subType = tempList.get(i).getJpSubType();
                        if (ValidateUtil.isNull(subType)) {
                            subType = "";
                        }
//                        String sysAppKey = SysCustomerCache.getInstance().getDefaultKey();
                        try {
                            JPushClient.getInstance().setSysCustomer(sysAppKey + "-" + tempList.get(i).getPushUserType() + subType).setPhones(userSet).setTitle(tempList.get(i).getTitle()).setContent(tempList.get(i).getContent()).pushByAlias();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                        //智慧商户
                        HashSet<String> userSet2 = new HashSet<>();
                        Iterator<String> it = userSet.iterator();
                        while (it.hasNext()) {
                            String str = it.next();
                            userSet2.add(jpushPhonePrefix + str);
                        }
                        try {
                            JPushClient.getInstance().setSysCustomer("o2o_jinyou-" + tempList.get(i).getPushUserType() + subType).setPhones(userSet2).setTitle(tempList.get(i).getTitle()).setContent(tempList.get(i).getContent()).pushByAlias();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }


                    }
                }
                tempList = null;
            }
        } else {
//            System.out.println("未开启推送");
        }
    }


    //定时执行(所有未确定商家的订单推送给商家)
    //秒  分  时  日  月  星期几  年
    @Scheduled(cron = "10 * * * * *")
    public void jPushAllSThread() {
        if (null == SYS_SETTINGS.IS_PUSH_WITH_JPUSH) {
            return;
        }

        if (0 != 1 - SYS_SETTINGS.IS_PUSH_WITH_JPUSH) {//未开启推送
            return;
        }

        if (null == SYS_SETTINGS.GOODS_ORDER_NOT_SURE_SHOP
                || (null != SYS_SETTINGS.GOODS_ORDER_NOT_SURE_SHOP && 0 == 1 - SYS_SETTINGS.GOODS_ORDER_NOT_SURE_SHOP)) {//外卖订单提交的时候商家是不确定的 0不确定 1确定
            return;
        }
        String sysAppKey = SysCustomerCache.getInstance().getDefaultKey();
        SysCustomerInfo info = SysCustomerCache.getInstance().getInfo(sysAppKey);
        String jpushPhonePrefix = sysAppKey;
        if (null != info && ValidateUtil.isNotNull(info.getJpushPhonePrefix())) {
            jpushPhonePrefix = info.getJpushPhonePrefix();
        }

        HashSet<String> shopUsernameList = new HashSet<>();
        HashSet<String> shopUsernameList2 = new HashSet<>();
        //商家管理方式
        if (null != SYS_SETTINGS.SHOP_MANAGE_TYPE && 0 == SYS_SETTINGS.SHOP_MANAGE_TYPE - SHOP_MANAGE_TYPE_FREE_OR_AGENT.AGENT) {
            //按商圈
            List<Long> agentList = OrderInfoMemory.getInstance().getAllNoShopSureAgent();
            if (ValidateUtil.isAbsList(agentList)) {
                //根据agentId 获取下面的店铺列表
                List<Long> shopIdList = new ArrayList<>();
                for (int i = 0; i < agentList.size(); i++) {
                    if (ValidateUtil.isNotID(agentList.get(i))) {
                        continue;
                    }
                    //
                    List<Long> tmpShopIdList = ShopAgentRelationMemory.getInstance().listOfAgentId(agentList.get(i));
                    if (ValidateUtil.isAbsList(tmpShopIdList)) {
                        shopIdList.addAll(tmpShopIdList);
                    }
                }
                if (ValidateUtil.isAbsList(shopIdList)) {
                    for (int i = 0; i < shopIdList.size(); i++) {
                        if (ValidateUtil.isNotID(shopIdList.get(i))) {
                            continue;
                        }
                        ShopInfo shopInfo = ShopMemory.getInstance().getShopById(shopIdList.get(i));
                        if (null == shopInfo) {
                            continue;
                        }
                        if (0 != 1 - shopInfo.getIsLock()) {
                            continue;
                        }
                        System.out.println("推给店铺：" + shopInfo.getCity() + "  " + shopInfo.getOwnUsername());
                        shopUsernameList.add(shopInfo.getOwnUsername());
                        shopUsernameList2.add(jpushPhonePrefix + shopInfo.getOwnUsername());
                    }
                }
            }
        } else {
            //按城市
            List<String> cityList = OrderInfoMemory.getInstance().getAllNoShopSureCity();
            if (ValidateUtil.isAbsList(cityList)) {
                for (int i = 0; i < cityList.size(); i++) {
                    if (ValidateUtil.isNull(cityList.get(i))) {
                        continue;
                    }
                    if (ValidateUtil.isNotNull(cityList.get(i))) {//如果是推给某个城市的
                        // List<ShopInfo> shopList = ShopMemory.getInstance().list(cityList.get(i), null, null, null, false);
                        List<ShopInfo> shopList = ShopMemory.getInstance().list(false, null, cityList.get(i), null, null, null, true, false, false, false);
                        if (ValidateUtil.isAbsList(shopList)) {
                            if (null == shopUsernameList) {
                                shopUsernameList = new HashSet<>();
                            }

                            for (int j = 0; j < shopList.size(); j++) {
                                if (null == shopList.get(j)) {
                                    continue;
                                }
                                if (0 != 1 - shopList.get(j).getIsWork()) {
                                    continue;
                                }
                                System.out.println("推给店铺：" + cityList.get(i) + " " + shopList.get(j).getOwnUsername());
                                shopUsernameList.add(shopList.get(j).getOwnUsername());
                                shopUsernameList2.add(jpushPhonePrefix + shopList.get(j).getOwnUsername());
                            }
                        }
                    }
                }
            }
        }

        if (null == shopUsernameList || shopUsernameList.size() < 1) {
            return;
        }
        //极光推送
        try {
            JPushClient.getInstance().setSysCustomer(sysAppKey + "-" + JPushMessage.SHOP_OWNER).setPhones(shopUsernameList).setTitle("又有新的订单了").setContent("有新的订单，请尽快处理").pushByAlias();
            JPushClient.getInstance().setSysCustomer("o2o_jinyou-" + JPushMessage.SHOP_OWNER).setPhones(shopUsernameList2).setTitle("又有新的订单了").setContent("有新的订单，请尽快处理").pushByAlias();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

// cancel by zhuwx （只推送一次）
//    //定时执行  (所有商家未接单)
//    //秒  分  时  日  月  星期几  年
//    @Scheduled(cron = "0 * * * * *")
//    public void jPushAllThread() {
//        if (null == SYS_SETTINGS.IS_PUSH_WITH_JPUSH) {
//            return;
//        }
//
//        if (0 != 1 - SYS_SETTINGS.IS_PUSH_WITH_JPUSH) {//未开启推送
//            return;
//        }
//
//        ConcurrentHashMap<Long, HashSet<String>> shopNotSureMap = OrderInfoMemory.getInstance().getAllShopNotSureOrder();
//        if (null == shopNotSureMap) {
//            return;
//        }
//        if (shopNotSureMap.size() <= 0) {
//            return;
//        }
//
////        List<String> shopUsernameList = new ArrayList<>();
////        synchronized (shopNotSureMap) {
////            for (Map.Entry<Long, HashSet<String>> data : shopNotSureMap.entrySet()) {
////                Long key = data.getKey();
////                if (null == data.getValue()) {
////                    continue;
////                }
////                if (data.getValue().size() <= 0) {
////                    continue;
////                }
////                ShopInfo shopInfo = ShopMemory.getInstance().getShopById(key);
////                if (null == shopInfo) {
////                    continue;
////                }
////                shopUsernameList.add(shopInfo.getOwnUsername());
////            }
////        }
////
////        if (!ValidateUtil.isAbsList(shopUsernameList)) {
////            return;
////        }
////        //极光推送
////        JPushMessage jPushMessage = new JPushMessage(shopUsernameList, "又有新的订单了", "有新的订单，请尽快处理");
////        jPushMessage.setPushUserType(JPushMessage.SHOP_OWNER);//发给店主
////        JPushTask.jPushMessageList.add(jPushMessage);
//
//        String sysAppKey = SysCustomerCache.getInstance().getDefaultKey();
//
//        HashSet<String> shopUsernameList = new HashSet<>();
//        HashSet<String> shopUsernameList2 = new HashSet<>();
//        synchronized (shopNotSureMap) {
//            for (Map.Entry<Long, HashSet<String>> data : shopNotSureMap.entrySet()) {
//                Long key = data.getKey();
//                if (null == data.getValue()) {
//                    continue;
//                }
//                if (data.getValue().size() <= 0) {
//                    continue;
//                }
//                ShopInfo shopInfo = ShopMemory.getInstance().getShopById(key);
//                if (null == shopInfo) {
//                    continue;
//                }
//                shopUsernameList.add(shopInfo.getOwnUsername());
//                shopUsernameList2.add(sysAppKey + shopInfo.getOwnUsername());
//
//                System.out.println("推送给商家:" + sysAppKey + "   " + shopInfo.getOwnUsername() + "，有未接单：" + data.getValue().size());
//            }
//        }
//
//        if (null == shopUsernameList || shopUsernameList.size() < 1) {
//            return;
//        }
//
//
////        if (ValidateUtil.isNull(sysAppKey)) {
////            sysAppKey = SysCustomerCache.getInstance().getDefaultKey();
////        }
//        try {
//            JPushClient.getInstance().setSysCustomer(sysAppKey + "-" + JPushMessage.SHOP_OWNER).setPhones(shopUsernameList).setTitle("又有新的订单了").setContent("有新的订单，请尽快处理").pushByAlias();
//            JPushClient.getInstance().setSysCustomer("o2o_jinyou-" + JPushMessage.SHOP_OWNER).setPhones(shopUsernameList2).setTitle("又有新的订单了").setContent("有新的订单，请尽快处理").pushByAlias();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }

//    //定时执行  (所有骑手未抢单)
//    //秒  分  时  日  月  星期几  年
//    @Scheduled(cron = "0 * * * * *")
//    public void jPushAllPostmanThread() {
//        if (null == SYS_SETTINGS.IS_PUSH_WITH_JPUSH && 0 != 1 - SYS_SETTINGS.IS_PUSH_WITH_JPUSH) {
//            return;
//        }
//        if (null == SYS_SETTINGS.IS_PUSH_WITH_JPUSH_2_POSTMAN && 0 != 1 - SYS_SETTINGS.IS_PUSH_WITH_JPUSH_2_POSTMAN) {
//            return;
//        }
//        // 若是仅调度模式 将不能看见商圈内的新订单
//        if (SYS_SETTINGS.GRAB_ORDER_MODE != null && GRAB_ORDER_MODE.ONLY_DISPATCH_MODE == SYS_SETTINGS.GRAB_ORDER_MODE) {
//            return;
//        }
//
//        ConcurrentHashMap<Long, HashSet<String>> agentUnDeliveryOrderMap = OrderInfoMemory.getInstance().getAllAgentUnDeliveryOrder();
//        if (null == agentUnDeliveryOrderMap || agentUnDeliveryOrderMap.size() < 0) {
//            return;
//        }
//
//        String sysAppKey = SysCustomerCache.getInstance().getDefaultKey();
//
//        HashSet<String> postUsernameSet = new HashSet<>();
//        HashSet<String> postUsernameSet2 = new HashSet<>();
//        synchronized (agentUnDeliveryOrderMap) {
//            for (Map.Entry<Long, HashSet<String>> data : agentUnDeliveryOrderMap.entrySet()) {
//                if (null == data) {
//                    continue;
//                }
//                Long agentId = data.getKey();
//                if (null == data.getValue()) {
//                    continue;
//                }
//                if (data.getValue().size() <= 0) {
//                    continue;
//                }
//                // 根据商圈id获取商圈里的骑手
//                List<String> postmanUsernameList = PostmanAgentRelationMemory.getInstance().listOfAgentId(agentId);
//                if (!ValidateUtil.isAbsList(postmanUsernameList)) {
//                    continue;
//                }
//
//                for (int i = 0; i < postmanUsernameList.size(); i++) {
//                    String username = postmanUsernameList.get(i);
//                    if (ValidateUtil.isNull(username)) {
//                        continue;
//                    }
//
//                    CityPostman cityPostman = CityPostmanMemory.getInstance().getPostman(username);
//                    if (null == cityPostman) {
//                        continue;
//                    }
//                    // 下班或忙碌的骑手不再推送
//                    if (0 == POSTMAN_WORK_STATUS.POSTMAN_WORK - cityPostman.getIsWork()) {
//                        postUsernameSet.add(username);
//                        postUsernameSet2.add(sysAppKey + username);
//                    }
//                }
//            }
//        }
//
//        if (null == postUsernameSet || postUsernameSet.size() < 1) {
//            return;
//        }
//
//        try {
//            JPushClient.getInstance().setSysCustomer(sysAppKey + "-" + JPushMessage.POSTMAN).setPhones(postUsernameSet).setTitle("又有新的订单了").setContent("有新的订单，快去抢单吧").pushByAlias();
//            JPushClient.getInstance().setSysCustomer("o2o_jinyou-" + JPushMessage.POSTMAN).setPhones(postUsernameSet2).setTitle("又有新的订单了").setContent("有新的订单，快去抢单吧").pushByAlias();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }

    //========================================================

    //   //定时执行。每隔20s 执行一次
//    //秒  分  时  日  月  星期几  年
//    @Scheduled(cron = "0/10 * * * * *")
//    public void jPushThread() {
//        if (null == SYS_SETTINGS.IS_PUSH_WITH_JPUSH) {
////            System.out.println("未设置推送");
//            return;
//        }
//
//        if (0 == 1 - SYS_SETTINGS.IS_PUSH_WITH_JPUSH) {         // 开启极光推送
////            System.out.println("jpush");
//            //测试
////            JPushServiceInterface jPushServiceInterface = DubboService.getInstance().getJPushServiceInterface();
////            jPushServiceInterface.pushOneUser("13333333333", "hhh", "试试", UserType.SHOP_OWNER);
//
//            if (jPushMessageList.size() > 0) {
//                List<JPushMessage> tempList = new ArrayList<JPushMessage>(jPushMessageList.size());
//                synchronized (jPushMessageList) {
//                    if (jPushMessageList.size() > 0) {
//                        tempList.addAll(jPushMessageList);
//                        jPushMessageList.clear();
//                    }
//                }
//
//                if (null != tempList && tempList.size() > 0) {
//                } else {
//                    return;
//                }
//
//                JPushServiceInterface jPushServiceInterface = DubboService.getInstance().getJPushServiceInterface();
//                if (null == jPushServiceInterface) {
//                    return;
//                }
//                for (int i = 0; i < tempList.size(); i++) {
//                    if (null == tempList.get(i)) {
//                        continue;
//                    }
//
////                    String username = null;
////                    List<String> usernameList = null;
////                    if (tempList.get(i).getIsCitySeller()) {//如果是推给某个城市的
//////                    String city = tempList.get(i).getCity();
//////                    if (ValidateUtil.isNull(city)) {
//////                        continue;
//////                    }
//////                    usernameList = new ArrayList<String>();
//////                    List<CityPostman> sellerLocalList = CityPostmanMemory.getInstance().listOfCity(city);
//////                    if (ValidateUtil.isAbsList(sellerLocalList)) {
//////                        for (int j = 0; j < sellerLocalList.size(); j++) {
//////                            if (null == sellerLocalList.get(j)) {
//////                                continue;
//////                            }
////////                            if (ValidateUtil.isNotNull(sellerLocalList.get(j).getSellerUsername())) {
////////                                if (CityPostmanMemory.getInstance().hasTypeOfSeller(sellerLocalList.get(j).getSellerId(), tempList.get(i).getPushUserInnerType())) {
////////                                    usernameList.add(sellerLocalList.get(j).getSellerUsername());
////////                                }
////////                            }
//////                        }
//////                    }
////                    } else {
////                        username = tempList.get(i).getUsername();
////                        usernameList = tempList.get(i).getUsernameList();
////                    }
//
//                    String username = tempList.get(i).getUsername();
//                    List<String> usernameList = tempList.get(i).getUsernameList();
//
//                    if (ValidateUtil.isNotAbsInteger(tempList.get(i).getPushUserType())) {
////                        System.out.println("未设置推送给的用户类型");
//                        continue;
//                    }
//                    switch (tempList.get(i).getPushUserType()) {
//                        case UserType.USER: {//用户
//                            if (null == SYS_SETTINGS.IS_PUSH_WITH_JPUSH_2_USER) {
////                                System.out.println("未开启用户推送");
//                                continue;
//                            }
//                            if (0 != 1 - SYS_SETTINGS.IS_PUSH_WITH_JPUSH_2_USER) {
////                                System.out.println("未开启用户推送2");
//                                continue;
//                            }
//                        }
//                        break;
//                        case UserType.SHOP_OWNER: {//店家
//                            if (null == SYS_SETTINGS.IS_PUSH_WITH_JPUSH_2_SHOP) {
////                                System.out.println("未开启店铺推送");
//                                continue;
//                            }
//                            if (0 != 1 - SYS_SETTINGS.IS_PUSH_WITH_JPUSH_2_POSTMAN) {
////                                System.out.println("未开启店铺推送2");
//                                continue;
//                            }
//
//
//                            if (tempList.get(i).getIsCitySeller() && ValidateUtil.isNotNull(tempList.get(i).getCity())) {//如果是推给某个城市的
//                                List<ShopInfo> postmanList = ShopMemory.getInstance().list(tempList.get(i).getCity(), null, null, null, false);
//                                if (ValidateUtil.isAbsList(postmanList)) {
//                                    if (null == usernameList) {
//                                        usernameList = new ArrayList<>();
//                                    }
//
//                                    for (int j = 0; j < postmanList.size(); j++) {
//                                        if (null == postmanList.get(j)) {
//                                            continue;
//                                        }
//                                        if (0 != 1 - postmanList.get(j).getIsWork()) {
//                                            continue;
//                                        }
//                                        System.out.println("推给店铺：" + postmanList.get(j).getOwnUsername());
//                                        usernameList.add(postmanList.get(j).getOwnUsername());
//                                    }
//                                }
//                            }
//                        }
//                        break;
//                        case UserType.POSTMAN: {//配送员
//                            if (tempList.get(i).getIsCitySeller() && ValidateUtil.isNotNull(tempList.get(i).getCity())) {//如果是推给某个城市的
//                                List<CityPostman> postmanList = CityPostmanMemory.getInstance().listOfCity(tempList.get(i).getCity());
//                                if (ValidateUtil.isAbsList(postmanList)) {
//                                    if (null == usernameList) {
//                                        usernameList = new ArrayList<>();
//                                    }
//
//                                    for (int j = 0; j < postmanList.size(); j++) {
//                                        if (null == postmanList.get(j)) {
//                                            continue;
//                                        }
//                                        if (0 != 1 - postmanList.get(j).getIsWork()) {
//                                            continue;
//                                        }
//                                        System.out.println("推给配送员：" + postmanList.get(j).getUsername());
//                                        usernameList.add(postmanList.get(j).getUsername());
//                                    }
//                                }
//                            }
//                            if (null == SYS_SETTINGS.IS_PUSH_WITH_JPUSH_2_POSTMAN) {
////                                System.out.println("未开启配送推送");
//                                continue;
//                            }
//                            if (0 != 1 - SYS_SETTINGS.IS_PUSH_WITH_JPUSH_2_POSTMAN) {
////                                System.out.println("未开启配送推送2");
//                                continue;
//                            }
//                        }
//                        break;
//                        default: {
////                            System.out.println("没有符合的推送");
//                            continue;
//                        }
//                    }
//
//
//                    //推给某人
//                    if (ValidateUtil.isNotNull(username)) {
//                        jPushServiceInterface.pushOneUser(username, tempList.get(i).getTitle(), tempList.get(i).getContent(), tempList.get(i).getPushUserType());
//                    }
//                    //推给某些人
//                    if (ValidateUtil.isAbsList(usernameList)) {
//                        jPushServiceInterface.pushSomeUser(usernameList, tempList.get(i).getTitle(), tempList.get(i).getContent(), tempList.get(i).getPushUserType());
//                    }
//                }
//                tempList = null;
//            }
//        } else {
////            System.out.println("未开启推送");
//        }
//    }


//    //定时执行。每隔20s 执行一次(所有未确定商家的订单推送给商家)
//    //秒  分  时  日  月  星期几  年
//    @Scheduled(cron = "10 * * * * *")
//    public void jPushAllSThread() {
//        if (null == SYS_SETTINGS.IS_PUSH_WITH_JPUSH) {
//            return;
//        }
//
//        if (0 != 1 - SYS_SETTINGS.IS_PUSH_WITH_JPUSH) {//未开启推送
//            return;
//        }
//
//        if (null == SYS_SETTINGS.GOODS_ORDER_NOT_SURE_SHOP
//                || (null != SYS_SETTINGS.GOODS_ORDER_NOT_SURE_SHOP && 0 == 1 - SYS_SETTINGS.GOODS_ORDER_NOT_SURE_SHOP)) {//外卖订单提交的时候商家是不确定的 0不确定 1确定
//            return;
//        }
//
//        List<String> shopUsernameList = new ArrayList<>();
//        //商家管理方式
//        if (null != SYS_SETTINGS.POSTMAN_IN_CITY_OR_AGENT && 0 == SYS_SETTINGS.POSTMAN_IN_CITY_OR_AGENT - POSTMAN_IN_CITY_OR_AGENT_DATA.AGENT) {
//            //按商圈
//            List<Long> agentList = OrderInfoMemory.getInstance().getAllNoShopSureAgent();
//            if (ValidateUtil.isAbsList(agentList)) {
//                //根据agentId 获取下面的店铺列表
//                List<Long> shopIdList = new ArrayList<>();
//                for (int i = 0; i < agentList.size(); i++) {
//                    if (ValidateUtil.isNotID(agentList.get(i))) {
//                        continue;
//                    }
//                    //
//                    List<Long> tmpShopIdList = ShopAgentRelationMemory.getInstance().listOfAgentId(agentList.get(i));
//                    if (ValidateUtil.isAbsList(tmpShopIdList)) {
//                        shopIdList.addAll(tmpShopIdList);
//                    }
//                }
//                if (ValidateUtil.isAbsList(shopIdList)) {
//                    for (int i = 0; i < shopIdList.size(); i++) {
//                        if (ValidateUtil.isNotID(shopIdList.get(i))) {
//                            continue;
//                        }
//                        ShopInfo shopInfo = ShopMemory.getInstance().getShopById(shopIdList.get(i));
//                        if (null == shopInfo) {
//                            continue;
//                        }
//                        if (0 != 1 - shopInfo.getIsLock()) {
//                            continue;
//                        }
//                        System.out.println("推给店铺：" + shopInfo.getCity() + "  " + shopInfo.getOwnUsername());
//                        shopUsernameList.add(shopInfo.getOwnUsername());
//                    }
//                }
//            }
//        } else {
//            //按城市
//            List<String> cityList = OrderInfoMemory.getInstance().getAllNoShopSureCity();
//            if (ValidateUtil.isAbsList(cityList)) {
//                for (int i = 0; i < cityList.size(); i++) {
//                    if (ValidateUtil.isNull(cityList.get(i))) {
//                        continue;
//                    }
//                    if (ValidateUtil.isNotNull(cityList.get(i))) {//如果是推给某个城市的
//                        List<ShopInfo> shopList = ShopMemory.getInstance().list(cityList.get(i), null, null, null, false);
//                        if (ValidateUtil.isAbsList(shopList)) {
//                            if (null == shopUsernameList) {
//                                shopUsernameList = new ArrayList<>();
//                            }
//
//                            for (int j = 0; j < shopList.size(); j++) {
//                                if (null == shopList.get(j)) {
//                                    continue;
//                                }
//                                if (0 != 1 - shopList.get(j).getIsWork()) {
//                                    continue;
//                                }
//                                System.out.println("推给店铺：" + cityList.get(i) + " " + shopList.get(j).getOwnUsername());
//                                shopUsernameList.add(shopList.get(j).getOwnUsername());
//                            }
//                        }
//                    }
//                }
//            }
//        }
//
//        if (!ValidateUtil.isAbsList(shopUsernameList)) {
//            return;
//        }
//        //极光推送
//        JPushMessage jPushMessage = new JPushMessage(shopUsernameList, "又有新的订单了", "有新的订单，请尽快处理");
//        jPushMessage.setPushUserType(JPushMessage.SHOP_OWNER);//发给店主
//        JPushTask.jPushMessageList.add(jPushMessage);
//    }

}
